package com.example.dingzexi_homework1;
import java.util.List;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;

public class FriendsFragment extends Fragment {

    private RecyclerView recyclerView;
    private FriendListAdapter adapter;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_friends, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        recyclerView = view.findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        recyclerView.setAdapter(new FriendListAdapter(getContext(), createFriendList()));
    }

    private List<Friend> createFriendList() {
        List<Friend> friends = new ArrayList<>();
        friends.add(new Friend("女朋友", R.drawable.image1,  "再不回我消息你就完了。         6小时前                      "));
        friends.add(new Friend("吃鸡大神", R.drawable.image2,"再不上号，我就不带你了。        3小时前                      "));
        friends.add(new Friend("秦始皇", R.drawable.image3,  "v我五百封你当大将军。          20分钟前                     "));
        friends.add(new Friend("同学", R.drawable.image4,   "把你安卓作业的源代码发我。       刚刚                       "));
        friends.add(new Friend("中国移动", R.drawable.image5,"中国移动祝您生日快乐。         3分钟前                     "));
        friends.add(new Friend("姐姐", R.drawable.image6,"记得溜一下绵绵和马甲。            昨天                         "));
        return friends;
    }
}